Mustache
Inspired by ctemplate and et, Mustache is a framework-agnostic way
to render logic-free views.
As ctemplates says, "It emphasizes separating logic from presentation: it is
impossible to embed application logic in this template language."
rust-mustache is a rust implementation of Mustache.
Documentation
The different Mustache tags are documented at mustache(5).
Documentation for this library is here.
Install
Install it through Cargo!
[dependencies]
mustache = "*"
Basic example
extern crate mustache;
extern crate rustc_serialize;
use std::io;
use mustache::MapBuilder;
#[derive(RustcEncodable)]
struct Planet {
name: String,
}
fn main() {
let template = mustache::compile_str("hello {{name}}");
let planet = Planet { name: "Mercury".into() };
template.render(&mut io::stdout(), &planet).unwrap();
println!("");
let data = MapBuilder::new()
.insert_str("name", "Venus")
.build();
template.render_data(&mut io::stdout(), &data);
println!("");
let mut planets = vec!("Jupiter", "Mars", "Earth");
let data = MapBuilder::new()
.insert_fn("name", move |_| {
planets.pop().unwrap().into()
})
.build();
template.render_data(&mut io::stdout(), &data);
println!("");
template.render_data(&mut io::stdout(), &data);
println!("");
template.render_data(&mut io::stdout(), &data);
println!("");
}
Testing
Simply clone and run:
cargo test
If you want to run the test cases, you'll need the spec as well.
git submodule init
git submodule update
cargo test
License
See LICENSE File